class WishList < ActiveRecord::Base
  belongs_to :user
  has_many :wish_items

  validates_presence_of :user_id
  validates_presence_of :name
  validates_uniqueness_of :name, :scope => :user_id

  accepts_nested_attributes_for :wish_items, :reject_if => lambda { |a| a["text"].blank? }, :allow_destroy => true

  # Status
  #  0 - new - not saved object

  def self.default user_id
    WishList.new(name: "default", state: 0, user_id: user_id)
  end

  def eql?(wl)
    id == wl.id && user_id == wl.user_id && name == wl.name && wish_items == wl.wish_items
  end

  def ===(other)
    self.eql?(other)
  end

  def ==(other)
    self.eql?(other)
  end
end
